package com.nathan.crm.controller;

import com.nathan.base.BaseController;
import com.nathan.base.ResultInfo;
import com.nathan.crm.query.CustomerOrderQuery;
import com.nathan.crm.service.CustomerOrderService;
import com.nathan.crm.vo.CustomerOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("order")
public class CustomerOrderController extends BaseController {

    @Autowired
    private CustomerOrderService customerOrderService;

    /**
     * 显示所有客户订单
     * @param customerOrderQuery
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryACustomerOrderByParams(CustomerOrderQuery customerOrderQuery){
        return customerOrderService.queryByParamsForTable(customerOrderQuery);
    }

    /**
     * 打开添加客户订单页面
     * @param cusId
     * @return
     */
    @RequestMapping("addCustomerOrderPage")
    public String addCustomerOrderPage(Integer cusId, Model model){
        model.addAttribute("cusId",cusId);
        return "customer/order_add";
    }

    /**
     * 添加客户订单
     * @param customerOrder
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public ResultInfo addOrder(CustomerOrder customerOrder){
        customerOrderService.addCustomerOrder(customerOrder);
        return success("订单添加成功！");
    }

}
